package chixing.day16.homework.work2;

import java.io.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

public class FlowTest {
    public static void main(String[] args) throws IOException {
        List<Record> records = new ArrayList<>();

        //1.创建输入流
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream("E:\\2025-cx\\project\\PJ\\J01\\Javase\\Temp\\flow.txt")));
        //第一行标题不需要
        String title = bufferedReader.readLine();
        String line;
        String[] strings = null;
        while ((line = bufferedReader.readLine()) != null){
            strings = line.split("\\|");//将拿到的数据以 | 分割
            //将读取的数据存起来
            String recordId = strings[0];
            String userName = strings[1];
            String institutionId = strings[2];
            char gender =  strings[3].equals("1") ? 'M':'F';
            String serialNumber =  strings[4];
            String LocalDateTimeStr = strings[5];
            //获取出来的是String类型要转换为LocalDateTime类型
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
            LocalDateTime transactionDate = LocalDateTime.parse(LocalDateTimeStr, formatter);
            String transactionAmountStr = strings[6];
            //获取为String类型转换为Double类型
            double transactionAmount = Double.valueOf(transactionAmountStr);
            //将获取的数据创建为一个Record对象然后添加到list中
            Record record = new Record(recordId, userName, institutionId, gender, serialNumber, transactionDate, transactionAmount);
            records.add(record);
        }
        records.forEach(System.out::println);
    }
}
